package com.hermit.qmst.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hermit.qmst.R;
import com.hermit.qmst.tools.Common;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/10 0010.
 */
public class BottleImageAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> images = new ArrayList<>();

    public BottleImageAdapter(Context context, List<String> image) {
        this.mContext = context;
        if (image != null && image.size() > 0) {
            this.images = image;
        }
    }

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public Object getItem(int i) {return images.get(i);}

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        HolderImag holderImag = null;
        if (view == null) {
            holderImag = new HolderImag();
            view = LayoutInflater.from(mContext).inflate(R.layout.list_item_bottle_image, null);
            holderImag.mImageView = (ImageView) view.findViewById(R.id.iv_img);
            view.setTag(holderImag);
        } else {
            holderImag = (HolderImag) view.getTag();
        }
        x.image().bind(holderImag.mImageView, Common.mCommUrl + images.get(i));
        return view;
    }

    class HolderImag {
        ImageView mImageView;
    }

}
